package cn.weichuyu.snippet.encrypt.jasypt;

import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;

public class MainProcessor {
    public static void main(String[] args) {
        if (args == null || args.length != 2) {
            System.out.println("入参不正确，需要java -jar XXX.jar 秘钥 原文");
        }
//        String password = "XXX"; //填密钥
//        String data = "XXX"; //填想加密的字符串
        String password = args[0];
        String data = args[1];

        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        config.setPassword(password);
        config.setAlgorithm("PBEWithMD5AndDES");
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("1");
        config.setProviderName("SunJCE");
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setStringOutputType("base64");
        encryptor.setConfig(config);

        System.out.println("原文:" + data);
        String secret = encryptor.encrypt(data);
        System.out.println("秘文:" + secret);
//        secret = "XXX"; //解密时，填要解密的字符串，不带ENC和扩号
        String origin = encryptor.decrypt(secret);
        System.out.println("秘文解密验证(自己和原文比较，不对请联系我):" + origin);

        System.out.println("完成");
    }
}
